using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Service.IService.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Model.Dto.Business.ProductionControl;

//创建时间：2024-09-29
namespace ZR.Admin.WebApi.Controllers.Business.ProductionControl
{
    /// <summary>
    /// 通信配置
    /// </summary>
    [Verify]
    [Route("formula/communicationconfig")]
    [ApiExplorerSettings(GroupName = "business")]
    public class CommunicationConfigController : BaseController
    {
        /// <summary>
        /// 通信配置接口
        /// </summary>
        private readonly ICommunicationConfigService _CommunicationConfigService;

        public CommunicationConfigController(ICommunicationConfigService CommunicationConfigService)
        {
            _CommunicationConfigService = CommunicationConfigService;
        }

        /// <summary>
        /// 查询通信配置列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "formula:communicationconfig:list")]
        public IActionResult QueryCommunicationConfig([FromQuery] CommunicationConfigQueryDto parm)
        {
            var response = _CommunicationConfigService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询通信配置详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "formula:communicationconfig:query")]
        public IActionResult GetCommunicationConfig(int Id)
        {
            var response = _CommunicationConfigService.GetInfo(Id);

            var info = response.Adapt<CommunicationConfigDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加通信配置
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "formula:communicationconfig:add")]
        [Log(Title = "通信配置", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCommunicationConfig([FromBody] CommunicationConfigDto parm)
        {
            var modal = parm.Adapt<CommunicationConfig>().ToCreate(HttpContext);

            var response = _CommunicationConfigService.AddCommunicationConfig(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新通信配置
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "formula:communicationconfig:edit")]
        [Log(Title = "通信配置", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCommunicationConfig([FromBody] CommunicationConfigDto parm)
        {
            var modal = parm.Adapt<CommunicationConfig>().ToUpdate(HttpContext);
            var response = _CommunicationConfigService.UpdateCommunicationConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除通信配置
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "formula:communicationconfig:delete")]
        [Log(Title = "通信配置", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCommunicationConfig([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CommunicationConfigService.Delete(idArr));
        }
    }
}